package com.faner.sys;

import com.faner.source.SpringSourceCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class FunFilter extends SpringSourceCode implements Filter {

    private static Logger logger = LoggerFactory.getLogger(FunFilter.class);

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        logger.info("过滤器初始化了----");
    }

    @Override
    public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) arg0;
        HttpServletResponse response = (HttpServletResponse) arg1;
        String ipAddr = getIpAddr(request);
        String requestURI = request.getRequestURI();
        int st = getMark();
        chain.doFilter(arg0, arg1);
        int et = getMark();
        logger.info(ipAddr + TAB + requestURI + TAB + "响应时间：" + (et - st));
    }

    @Override
    public void destroy() {
        logger.info("过滤器被销毁了----");
    }


}
